package ru.study.thinkin.chapter7;

class Shape {
	Shape(int i) {
		System.out.println("Конструктор Shape");
	}
	void dispose() {
		System.out.println("Стираем Shape");
	}	
}

class Circle extends Shape {
	Circle(int i) {
		super(i);
		System.out.println("Рисуем круг Circle");
	}
	void dispose() {
		System.out.println("Стираем окружность Circle");
		super.dispose();
	}
}

class Triangle extends Shape {

	public Triangle(int i) {
		super(i);
		System.out.println("Рисуем треугольник");
	}
	@Override
	void dispose() {
		System.out.println("стираем треугольник");
		super.dispose();
	}	
}

class Line extends Shape {
	public int start,end;

	public Line(int start,int end) {
		super(start);
		this.start=start;
		this.end=end;
		System.out.println("рисуем линию "+start +" "+end);
	}
	void dispose() {
		System.out.println("стираем линию");
		super.dispose();
	}	
}

public class CADSystem extends Shape {
	private Circle cr;
	private Triangle tr;
	private Line[] lines = new Line[3];
	
	public CADSystem(int i) {
		super(i+1);
		for(int j =0;j<lines.length;j++ ) {
			lines[j]=new Line(j,j*j);			
		}
		cr = new Circle(1);
		tr = new Triangle(1);
		System.out.println("Комбинированный конструктор");
		
	}
	void dispose() {
		System.out.println("CAD dispose()");
		tr.dispose();
		cr.dispose();
		for(int i =lines.length-1;i>=0;i--) {
			lines[i].dispose();
		}
		super.dispose();
		System.out.println("============");
	}
	public static void main(String[] args) {
		CADSystem cd = new CADSystem(47);
		try {
			Line l = cd.lines[0];
			System.out.println(l.start);
			Line l2 = cd.lines[100];
		}
		finally{
			cd.dispose();
		}
	}
	
}

